package Demo5;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main24 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch=new CountDownLatch(10);

        ExecutorService executors=Executors.newFixedThreadPool(4);
        for (int i = 0;  i<10 ; i++) {
            int id=i;
            executors.submit(()->{
                System.out.println("子任务开始"+id);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("子任务结束"+id);
                latch.countDown();
            });
        }
latch.await();
        System.out.println("所有任务全部结束");

    }
}
